﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Department.App_Code;

namespace Department
{
    public partial class Search : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = "Търсене | Информационни технологии и комуникации";

            string search = Request.Params["q"].Trim();

            if (!Page.IsPostBack)
            {
                if ((search == null) || (search.Length > 256) || (search.Length < 3))
                {
                    NotFoundLabel.Visible = true; // invalid parameter entered
                }
                else
                {
                    DataTable dt = CallStoredProcedure.StoredProcSearch(search, DepartmentProperties.GetDepartmentID(Request));
                    ListSearch.DataSource = dt;
                    if (!(dt.Rows.Count == 0))
                    {
                        ListSearch.DataBind();
                    }
                    else
                    {
                        NotFoundLabel.Visible = true; // no items found
                    }
                }
            }


        }
        protected void ListSearch_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            pagerListSearch.Visible = (pagerListSearch.PageSize < pagerListSearch.TotalRowCount);
        }
    }
}